import logging

from config import BASE_HOST


class RegLoginApi:

    def __init__(self, ses):
        self.ses = ses

    # 获取图片验证码接口
    def get_img_verify_code(self, r):
        url = BASE_HOST + f"/common/public/verifycode1/{r}"
        resp = self.ses.get(url=url)
        logging.info(f"获取图片验证码接口返回响应状态码:{resp.status_code}")
        return resp

    # 获取短信验证码接口
    def get_phone_verify_code(self, phone_v, img_code_v, type_v="reg"):
        url = BASE_HOST + "/member/public/sendSms"
        form_dict = {"phone": phone_v, "imgVerifyCode": img_code_v, "type": type_v}
        resp = self.ses.post(url=url, data=form_dict)
        logging.info(f"获取短信验证码接口返回响应状态码:{resp.status_code}")
        return resp

    # 注册接口
    def user_register(self, form_dict):
        url = BASE_HOST + "/member/public/reg"
        resp = self.ses.post(url=url, data=form_dict)
        logging.info(f"注册接口返回响应状态码:{resp.status_code}")
        return resp

    # 登录接口
    def user_login(self, username_v, pwd_v):
        url = BASE_HOST + "/member/public/login"
        from_dict = {"keywords": username_v, "password": pwd_v}
        resp = self.ses.post(url=url, data=from_dict)
        logging.info(f"登录接口返回响应状态码:{resp.json()}")
        return resp
